package com.dycong.common.leetcode.yi;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: yilin
 * Date: 2019-09-04
 * Time: 20:01
 */
public class GUPIao {

    public int maxProfit(int[] prices) {
        if (prices == null || prices.length <= 0) return 0;
        int buyMin = prices[0];
        int sellMax = 0;
        for (int i = 1; i < prices.length; i++) {
            buyMin = Math.min(prices[i], buyMin);
            sellMax = Math.max(sellMax, prices[i] - buyMin);
        }
        return sellMax;

    }
}
